<?php
/**
 * Created by PhpStorm.
 * User: fengyan
 * Date: 17-11-3
 * Time: 下午2:50
 */

namespace App\Models\Portal;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
    use SoftDeletes;

    protected $table = 'portal_category';

    /**
     * 文档
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function document()
    {
        return $this->hasMany('\\App\\Models\\Portal\\Document', 'category_id', 'id');
    }

    /**
     * 封面图片
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function cover()
    {
        return $this->belongsTo('\\App\\Models\\Basic\\Resource', 'cover_id', 'id')->select(['resource_type', 'resource_name', 'resource_path']);
    }

    /**
     * 单网页
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function page()
    {
        return $this->hasOne('\\App\\Models\\Portal\\Page', 'id', 'id');
    }
}